﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.IRepository.SystemManager;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.Repository.CommonLib;

namespace SystemCenterSoa.Repository.SystemManager
{
    public class PerformanceRepository : BaseRepository, IPerformanceRepository
    {
        public PerformanceRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {

        }
        //添加考核任务
        public bool AddTheAssessmentTask(TheAssessmentTask theAssessmentTask)
        {
            _systemCenterDbSoaContext.TheAssessmentTask.Add(theAssessmentTask);
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        //删除考核任务
        public bool DelTheAssessmentTask(int id)
        {
            var k = _systemCenterDbSoaContext.TheAssessmentTask.Where(t=>t.ItemNumber==id).FirstOrDefault();
            _systemCenterDbSoaContext.Remove(k);
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        //显示考核统计
        public List<AssessmentTotal> ShowAssessmentTotal()
        {
            var list = _systemCenterDbSoaContext.AssessmentTotal.AsQueryable();
            return list.ToList();
        }
        //显示考核任务
        public List<TheAssessmentTask> ShowTheAssessmentTask()
        {
            var list = _systemCenterDbSoaContext.TheAssessmentTask.AsQueryable();
            return list.ToList();
        }
        //归档
        public bool UpdateGuiDang(int id)
        {
            var jid = _systemCenterDbSoaContext.TheAssessmentTask.FirstOrDefault(t => t.ItemNumber == id);
            if(jid!=null)
            {
                jid.Pigeonhole = 1;
            }
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        //修改考核任务
        public bool UpdateTheAssessmentTask(TheAssessmentTask theAssessmentTask)
        {
            _systemCenterDbSoaContext.Entry(theAssessmentTask).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
    }
}
